<template>
  <div id="app">
    <el-card shadow="hover" class="mgb20">
      <div class="head">
        <div>{{ $t("home.myProduction") }}</div>
        <div class="setBook" @click="goSet">
          <img style="margin-right:5px;margin-top:2px"  src="../../../assets/xsym.png" alt="" />
          {{ $t("home.newWork") }}
        </div>
      </div>
      <div v-if="bookList.length > 0" class="bookList_box">
        <div class="content">
          <!-- <router-view></router-view> -->
          <div v-for="(item, index) in bookList" :key="index">
            <div class="book">
              <div class="info">
                <div class="page_img">
                  <!-- <img :src='item.img' alt=""> -->
                  <img v-if="item.coverUrl" :src="item.coverUrl" alt="成功" />
                  <img v-else src="../../../assets/active.png" alt="失败" />
                  <!-- {{item.img}} -->
                </div>
                <div class="page_info">
                  <div class="title">
                    {{ item.bookTitle ? item.bookTitle : $t("home.booksName") }}
                  </div>
                  <div class="nameTitle">
                    <div>{{ item.lastChapterTitle }}</div>
                    <div>{{ item.lastChapterTime }}</div>
                  </div>
                </div>
              </div>
              <div class="control">
                <div class="status">
                  <!-- <el-tag
                  style="color: #F1403C; background-color: rgba(241, 64, 60, 0.1);border:none"
                  >{{$t("home.ban")}}</el-tag
                > -->
                  <!-- <el-tag
                  style="color: #F39B04; background-color: rgba(251, 160, 2, 0.2);border:none"
                  >{{$t("home.signed")}}</el-tag
                > -->
                  <el-tag
                    style="
                      color: #28b04c;
                      background-color: rgba(40, 176, 76, 0.1);
                      border: none;
                    "
                    >{{ $t("home.inTheSerial") }}</el-tag
                  >
                  <!-- <el-tag
                  style="color: #F1403C; background-color: rgba(241, 64, 60, 0.1);border:none"
                  >{{$t("home.ends")}}</el-tag
                > -->
                  <!-- <el-tag
                  v-if="item.isContract"
                  style="color: #ff9f6a; background-color: #fef5f0"
                  >{{$t("home.signed")}}</el-tag
                >
                <el-tag
                  v-if="!item.isOnline"
                  style="color: #c27ff9; background-color: #f2e8fa"
                  >{{$t("home.tapeOut")}}</el-tag
                >
                <el-tag
                 style="color: #28B04C; background-color: rgba(40, 176, 76, 0.1);"
                  >{{ item.writingProcess | writingProcess }}</el-tag
                >
                <el-tag
                  v-if="item.status == 3"
                  style="color: #ff9f6a; background-color: #fef5f0"
                  >{{$t("home.hasBeenFinished")}}</el-tag
                > -->
                </div>
                <div>
                  <el-button
                    :key="index"
                    v-if="item.writingProcess != 2"
                    @click="toBookSetting(item)"
                    >{{ $t("home.workSettings") }}</el-button
                  >
                  <el-button
                    v-if="item.isExistChapter == 1"
                    @click="toBookDraftChapter(item)"
                    >{{ $t("home.alreadySentChapters") }}</el-button
                  >
                  <el-button type="primary" @click="toWriteNewChapter(item)">{{
                    $t("home.writeNewChapter")
                  }}</el-button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div v-else class="no_content_box">
        <img
          src="../../../assets/bookManage/no_content.png"
          alt=""
          class="no_content"
        />
        <div class="no_content_text">
          There is no work at present. Go and create it!
        </div>
        <el-button type="primary" @click="goSet">New works</el-button>
      </div>
    </el-card>
  </div>
</template>

<script>
import lowNews from "@/page/home/component/lowNews.vue";
import { bookList, selectLatestChapter } from "@/api/authorCenter/createBook";
let that;
export default {
  name: "dashboard",
  data() {
    return {
      user: {
        mdays: 12,
        name: "zuozhe",
        days: 122,
        countnumber: 123123123,
        number: 12312,
      },
      bookList: [],
    };
  },
  filters: {
    writingProcess(res) {
      switch (res) {
        case 0:
          return that.$t("home.inTheSerial");
        case 1:
          return that.$t("home.hasBeenFinished");
        case 2:
          return that.$t("home.newConstruction");
      }
    },
  },
  beforeCreate() {
    that = this;
  },
  components: {
    lowNews: lowNews,
  },

  methods: {
    goSet() {
      this.$router.push("/author/bookManage/createBook");
    },
    toBookSetting(item) {
      this.$router.push({
        path: "/author/bookManage/bookSetting",
        query: {
          bookid: item.bookId,
        },
      });
    },
    toBookDraftChapter(item) {
      let params = { bookId: item.bookId };
      sessionStorage.removeItem("writeArticle");
      sessionStorage.setItem("writeArticle", JSON.stringify(item));
      selectLatestChapter(params).then((res) => {
        if (res.code == 1) {
          this.$router.push({
            path: "/writerTool",
            query: { contenId: res.source.id, state: res.source.state },
          });
        }
      });
    },
    toWriteNewChapter(item) {
      sessionStorage.removeItem("writeArticle");
      sessionStorage.setItem("writeArticle", JSON.stringify(item));
      this.$router.push({ path: "/writerTool" });
    },
    ApplayToUnBanBook(e) {
      alert(this.$t("home.theIdOfTheBook") + e.id);
    },
    //获取作评列表
    getBookList() {
      bookList().then((res) => {
        this.bookList = res.source;
      });
    },
  },
  created() {
    // this.getBookList();
  },
  mounted() {
    this.getBookList();
  },
};
</script>

<style scoped="scoped" lang="scss">
#app {
  height: 100%;
}
::v-deep .el-card {
  border: none;
  height: 100%;
}
.nameTitle {
  div:nth-child(1) {
    line-height: 35px;
    font-size: 14px;
    color: #333;
  }
  div:nth-child(2) {
    line-height: 35px;
    font-size: 1px;
    color: #ccc;
  }
}
.bookList_box {
  .el-button--primary {
    background-color: rgba(51, 133, 253, 0.1);
    border-color: #3385fd;
    color: #3385fd;
  }
}

.setBook {
  cursor: pointer;
  font-size: 18px;
  color: #3385fd;
}
.head {
  font-size: 24px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #333333;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid #f1f1f1;
}

.mgb20 {
  margin-bottom: 20px;
}

.content {
  .book {
    box-sizing: border-box;
    height: 140px;
    margin-left: 20px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    border-bottom: 1px solid #f1f1f1;

    .info {
      display: flex;
      flex-direction: row;
      align-items: center;
      .page_img {
        width: 82px;
        height: 110px;

        img {
          width: 100%;
          height: 100%;
          border-radius: 8px;
        }

        margin-right: 10px;
      }

      .page_info {
        .title {
          font-size: 18px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #333333;
          margin: 10px 0;
        }

        .context {
          font-size: 16px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #666666;
          line-height: 22px;
          margin-bottom: 17px;
        }

        .time {
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #cccccc;
          line-height: 20px;
        }
      }
    }

    .control {
      padding: 15px 0;
      box-sizing: border-box;
      display: flex;
      flex-direction: column;
      text-align: right;
      justify-content: space-between;

      .status {
        span {
          box-sizing: border-box;
          margin-left: 20px;
          padding: 0 20px;
        }

        .status_item {
          margin-right: 20px;
          padding: 0 20px;
        }
      }
    }
  }
}
.no_content_box {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 100px;
  .el-button--primary {
    width: 221px;
    height: 48px;
    font-size: 18px;
    margin-top: 82px;
  }
}
.no_content {
  width: 300px;
  height: 234px;
}
.no_content_text {
  font-size: 18px;
  color: #999999;
  margin-top: 30px;
}
</style>
